<?php
class Tourism_provider_model extends BZ_Model
{
    protected $table   = 'tourism_provider';
    protected $table_1 = 'user';
    
     /** 供应商类别
     * @param unknown $pgNum
     * @param unknown $num
     */
    public function findProvider($pgNum, $num)
    {
        $this->db->select('id,uid,name,detail,logo');
        $this->db->from($this->table);
        $this->db->where('flag', 1);
        $this->db->limit($pgNum, $num);
        $this->db->order_by('sort', 'desc');
        return $this->db->get();
    }
    
     /**
     * 获取供应商信息
     * @param unknown $uid
     */
    public function providerInforByUid($uid){
        $this->db->select('uid,name,detail,wap_image,logo');
        $this->db->where('uid',$uid);
        $this->db->where('flag', 1);
        return $this->db->get($this->table);
    }

    /**
     * 获取供应商信息
     */
    public function providerInforByUserName($userName)
    {
        $this->db->select('user.uid');
        $this->db->from($this->table);
        $this->db->join($this->table_1, 'user.uid=tourism_provider.uid');
        $this->db->where('user_name',$userName);
        $this->db->where('tourism_provider.flag', 1);
        $this->db->where('user.flag', 1);
        $this->db->limit(1);
        return $this->db->get();
    }

    /**
     * 查找供应商站点
     */
    public function getProvider($params)
    {
        $this->db->select('id');
        $this->db->from($this->table);
        if($params['uid']) {
            $this->db->where('uid',$params['uid']);
        }
        if ( !empty($params['limit'])) {
            $this->db->limit($params['limit']);
        }
        return $this->db->get();
    }
    

     /**
     * 发现供应商
     * @param unknown $pgNum
     * @param unknown $num
     * @param unknown $param
     */
    public function findProviderByReason($pgNum,$num,$param)
    {
        $this->db->select('id,uid,name,detail,logo,company_address,main_business');
        $this->db->from($this->table);
        $this->db->where('flag', 1);
        if( !empty($param['keyword']) ){
            $this->db->like('name',$param['keyword']);
        }
        if( !empty($param['category_id']) ){
            $this->db->where('category_id',$param['category_id']);
        }
        $this->db->limit($pgNum, $num);
        $this->db->order_by('sort', 'desc');
        return $this->db->get();
    }
}